import java.awt.Button;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.WindowConstants;


public class JSONtoCSV {

	public static JFrame frame;
	public static JPanel panel;
	public static JLabel label;
	public static JLabel label1;
	
	public static String show;
public static void main(String[] args)

{
	
	
	
	
	frame = new JFrame();
	panel = new JPanel();
	label1 = new JLabel();
	panel.add(label1);
frame.setTitle("JSON to CSV convertor");
frame.setVisible(true);
	frame.setSize(500,250);
	
	Button button = new Button("Convert to XLS");

	Button  button1 = new Button("Quit");
	
	Button  button3 = new Button("Choose JSON file");
	button3.setBounds(200,25, 100, 20);
	label1.setBounds(125,50 , 400, 50);

	panel.add(button3);
	button3.addActionListener(new FileChooser());
	
	
	panel.setLayout(null);
	panel.add(button);
	button.setBounds(100,120, 100, 20);

	panel.add(button1);
	button1.setBounds(300, 120, 100, 20);

	//JFileChooser fc = new JFileChooser();
	
	
	frame.add(panel);
	frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
	 label = new JLabel();
	label.setText("Developed By Abhishek and Jatin");
	label.setBounds(125,175 , 400, 50);
	panel.add(label);
	
	button.addActionListener(new CSVConvertor());
	button1.addActionListener(new CommandAction());
}
	
}

class CSVConvertor  implements ActionListener 
{
   public void actionPerformed(ActionEvent event)
   {
	   String ext[] = JSONtoCSV.show.split("\\.");
       if(ext[1].equals("json"))
       {
       	correct_json cj= new correct_json();
       	cj.correctJson(JSONtoCSV.show);
    	System.exit(0);
       }
       else
       {
       	System.out.println("File is not json");
       }
	    }
   }


class FileChooser  implements ActionListener 
{
   public void actionPerformed(ActionEvent event)
   {
	   JFileChooser open = new JFileChooser();
	    int option = open.showOpenDialog( JSONtoCSV.frame );
        JSONtoCSV.show=open.getSelectedFile().getPath();
        JSONtoCSV.label1.setText("Selected File is"+open.getSelectedFile().getName());
        
	    
	    }
   }



class CommandAction  implements ActionListener 
{
   public void actionPerformed(ActionEvent event)
   {
   	System.exit(0);
   }
   }


